package com.example.springboot.controller;


import com.example.springboot.entity.City;
import com.example.springboot.service.CityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Created by tang on 2017/12/4.
 */
@RestController
@RequestMapping("/city")
public class CityController {

    @Autowired
    private CityService cityService;

    @RequestMapping("/findOneCity")
    public City findOneCity(String cityName) {
        City city = cityService.findByCityName(cityName);
        return city;
    }

    @RequestMapping(value = "/findAll")
    public List<City> findAll() {
        return cityService.findAll();
    }

    @RequestMapping("/updateCity")
    public void updateCity() {
        City city = cityService.findByCityName("北京");
        city.setDescription("abc");
        cityService.updateCity(city);
    }

    @RequestMapping("/addCity")
    public void addCity() {
        City city = new City(1, "武汉", "热的要死");
        cityService.addCity(city);
    }
}
